package com.voltmao.energy.Controller;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jmx.support.MetricType;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.fasterxml.jackson.databind.Module;
import com.voltmao.energy.Dao.ApnCodeDAO;
import com.voltmao.energy.Dao.MeterInfo;
import com.voltmao.energy.Dao.VoltModule;
import com.voltmao.energy.Event.MyEventBus;
import com.voltmao.energy.Mapper.ApnCodeMapper;
import com.voltmao.energy.Service.ApnCodeService;
import com.voltmao.energy.Service.MeterInfoService;
import com.voltmao.energy.Service.VoltModuleService;

@Controller
@RequestMapping("/Index")
public class IndexController {
	@Resource
	private ApnCodeMapper mapper;
	@Resource
	private ApnCodeService apnser;
	@Resource
	private MeterInfoService meterService; 
	@Resource
	private VoltModuleService moduleService; 
	
	
	@RequestMapping("/test")
	@ResponseBody
	public Map<String, Object> testFun(@RequestParam(value = "id") String id){
		//确保用哪个register的就用哪个post
		MyEventBus.post(id);
		Integer in = 123;
		MyEventBus.post(in);
		
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("id", id);
		return map;
	}
	
	@RequestMapping("/test2")
	@ResponseBody
	public Map<String, Object> testFun2(){
		//确保用哪个register的就用哪个post
		System.out.println(moduleService.getModuleByPk(1));
//		VoltModule module = moduleService.getModuleByPk(1);
//		module.setIstabs(Byte.parseByte("1"));
//		module.setIsvisible(Byte.parseByte("0"));
//		module.setModuleOrder(Byte.parseByte("2"));
		VoltModule module = new VoltModule();
		module.setModuleName("模块名");
		moduleService.addModule(module);
		System.out.println(moduleService.getModuleByPk(1));
		return null;
	}
	@RequestMapping("/testsql")
	@ResponseBody
	public Map<String, Object> testSql(){
		List<ApnCodeDAO> lists = mapper.getAll();
		MeterInfo mmeter = meterService.getByPK(1L);
		
		Map<String,Object> map = new HashMap<String, Object>();
		map.put("lists", lists);
		map.put("lists2", mmeter);
		return map;
	}
	
	
	@RequestMapping(value="/index",method=RequestMethod.GET)
	public String index(ModelMap m){
		return "index";
	}
}
